﻿using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Web.UI;
using System.Reflection;

using Developmentalmadness.Web.UI.AjaxAbstractions;

namespace Developmentalmadness.Web.UI.ExtJsControlLibrary
{
    public class ExtJsDatePicker : ExtJsComponent
    {
        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.DatePicker";

            String[] properties = new String[]{
                "cancelText", "constrainToViewport", "dayNames", "disabledDatesRE", "disabledDatesText",
                "disabledDays", "disabledDaysText", "format", "maxDate", "maxText", "minDate", "minText",
                "monthNames", "monthYearText", "nextText", "okText", "prevText", "startDay", "todayText",
                "todayTip"
            };

            Type component = typeof(ExtJsDatePicker);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'Ext.DatePicker.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                    continue;

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

            return list;
        }


        #region Public Properties

        public String cancelText { get; set; }

        public Boolean? constrainToViewport { get; set; }

        public String dayNames { get; set; }

        public String disabledDatesRE { get; set; }

        public String disabledDatesText { get; set; }

        public String disabledDays { get; set; }

        public String disabledDaysText { get; set; }

        public String format { get; set; }

        public DateTime? maxDate { get; set; }

        public String maxText { get; set; }

        public DateTime? minDate { get; set; }

        public String minText { get; set; }

        public String monthNames { get; set; }

        public String monthYearText { get; set; }

        public String nextText { get; set; }

        public String okText { get; set; }

        public String prevText { get; set; }

        public Int32? startDay { get; set; }

        public String todayText { get; set; }

        public String todayTip { get; set; }

        #endregion
    }
}
